<template>
  <view class="carbox" v-if="cart.length">
    <!-- 收货地址组件 -->
    <my-address></my-address>
    <!-- 购物车标题 -->
    <view class="cart-title">
      <uni-icons type="shop" size="18"></uni-icons>
      <text>购物车</text>
    </view>
    <!-- 商品列表组件 -->
    <uni-swipe-action>
      <block v-for="(item,inx) in cart">
        <uni-swipe-action-item :options="options" @click="delGoodsFn(item.goods_id)">
          <my-goodslist @CheckedChangeFn="checkedChangeFn" @NumChangeFn="numChangeFn" :goods="item" :showRadio="true"
            :showNum="true"></my-goodslist>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 结算组件 -->
    <sumup></sumup>
  </view>
  <!-- 空空如也页面 -->
  <view class="empty_car" v-else>
    <image src="/static/cart_empty@2x.png" ></image>
    <text>空空如也~~</text>
  </view>
</template>

<script>
  import tbBadge from '@/mixins/tabbar_badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    mixins: [tbBadge],
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    data() {
      return {
      // 左滑删除项
      options:[{
        text:'删除',
        style:{
          backgroundColor:'#c00000'
        }
      }]
      }
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'goodsCountChange','delGoodsItem']),
      // 选择框改变事件
      checkedChangeFn(e) {
        this.updateGoodsState(e)
      },
      // 计数器改变事件
      numChangeFn(e) {
        this.goodsCountChange(e)
      },
      // 删除商品
      delGoodsFn(id){
        this.delGoodsItem(id)
      }
    }
  }
</script>

<style lang="scss">
  .carbox {
    padding-bottom: 50px;
    .cart-title {
      height: 40px;
      display: flex;
      align-items: center;
      font-size: 14px;
      padding-left: 5px;
      border-bottom: 1px solid #efefef;
    
      text {
        margin-left: 10px;
      }
    }
  }
  .empty_car {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 200px;
    image {
      width: 100px;
      height: 100px;
    }
    text {
      font-size: 12px;
      color: #777777;
      margin-top: 10px;
    }
  }
  
</style>
